Skip to content

Fix invalid JSON and YAML outputs for outdated command #2111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

lluiscampos
Copy link
Contributor

@lluiscampos lluiscampos commented Mar 15, 2023

Fixes issue #2104

The code for internal/cli/core and internal/cli/lib has been
refactored so that we can use only the Get functions from
internal/cli/outdated package and compose there composited object.

For regular text output, the new table will have some extra fields that
either for platforms or for libraries will be blank.

For JSON and YAML output, the resulting object will have the top-level
keys platforms and libraries which contain, respectively, the array
of outaded platforms and outdated libraries.

Please check if the PR fulfills these requirements

See how to contribute

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • configuration.schema.json updated if new parameters are added.

What kind of change does this PR introduce?

Fixes #2104

What is the current behavior?

outdated commands prints two tables for text mode, and two objects for JSON mode:

Text (default):

>>> Running: /home/lluis/go/src/github.com/arduino/arduino-cli/arduino-cli outdated
ID          Installed Latest Name
arduino:avr 1.6.3     1.8.6  Arduino AVR Boards

Name    Installed     Available     Location              Description
USBHost 1.0.0         1.0.5         LIBRARY_LOCATION_USER Allows the communication with USB per...

and JSON:

$ arduino-cli outdated --format json
[]
[
  {
    "library": {
      "name": "FastLED",
      "author": "Daniel Garcia",
      "maintainer": "Daniel Garcia \[email protected]\u003e",
      "sentence": "Multi-platform library for controlling dozens of different types of LEDs along with optimized math, effect, and noise functions.",
      "paragraph": "Multi-platform library for controlling dozens of different types of LEDs along with optimized math, effect, and noise functions.",
      "website": "https://github.com/FastLED/FastLED",
      "category": "Display",
      "architectures": [
        "*"
      ],
      "install_dir": "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED",
      "source_dir": "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED",
      "version": "3.3.2",
      "license": "Unspecified",
      "location": 1,
      "examples": [
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\AnalogOutput",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Blink",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\ColorPalette",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\ColorTemperature",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Cylon",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\DemoReel100",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Fire2012",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Fire2012WithPalette",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\FirstLight",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Multiple\\ArrayOfLedArrays",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Multiple\\MirroringSample",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Multiple\\MultiArrays",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Multiple\\MultipleStripsInOneArray",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Multiple\\OctoWS2811Demo",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Multiple\\ParallelOutputDemo",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Noise",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\NoisePlayground",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\NoisePlusPalette",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Pintest",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Ports\\PJRCSpectrumAnalyzer",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\RGBCalibrate",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\RGBSetDemo",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\SmartMatrix",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\XYMatrix"
      ],
      "provides_includes": [
        "FastLED.h",
        "bitswap.h",
        "chipsets.h",
        "color.h",
        "colorpalettes.h",
        "colorutils.h",
        "controller.h",
        "cpp_compat.h",
        "dmx.h",
        "fastled_config.h",
        "fastled_delay.h",
        "fastled_progmem.h",
        "fastpin.h",
        "fastspi.h",
        "fastspi_bitbang.h",
        "fastspi_dma.h",
        "fastspi_nop.h",
        "fastspi_ref.h",
        "fastspi_types.h",
        "hsv2rgb.h",
        "led_sysdefs.h",
        "lib8tion.h",
        "noise.h",
        "pixelset.h",
        "pixeltypes.h",
        "platforms.h",
        "power_mgt.h"
      ]
    },
    "release": {
      "author": "Daniel Garcia",
      "version": "3.5.0",
      "maintainer": "Daniel Garcia \[email protected]\u003e",
      "sentence": "Multi-platform library for controlling dozens of different types of LEDs along with optimized math, effect, and noise functions.",
      "paragraph": "Multi-platform library for controlling dozens of different types of LEDs along with optimized math, effect, and noise functions.",
      "website": "https://github.com/FastLED/FastLED",
      "category": "Display",
      "architectures": [
        "*"
      ],
      "types": [
        "Contributed"
      ]
    }
  }
]

What is the new behavior?

outdated commands prints one merged table for text mode, and one object for JSON mode:

Text (default):

>>> Running: /home/lluis/go/src/github.com/arduino/arduino-cli/arduino-cli outdated
ID          Name               Installed Latest Location              Description
arduino:avr Arduino AVR Boards 1.6.3     1.8.6
            USBHost            1.0.0     1.0.5  LIBRARY_LOCATION_USER Allows the communication with USB per...

and JSON:

./arduino-cli outdated --format json
[
  [],
  [
    {
      "library": {
        "architectures": [
          "*"
        ],
        "author": "Daniel Garcia",
        "category": "Display",
        "examples": [
          "/home/lluis/Arduino/libraries/FastLED/examples/AnalogOutput",
          "/home/lluis/Arduino/libraries/FastLED/examples/Blink",
          "/home/lluis/Arduino/libraries/FastLED/examples/ColorPalette",
          "/home/lluis/Arduino/libraries/FastLED/examples/ColorTemperature",
          "/home/lluis/Arduino/libraries/FastLED/examples/Cylon",
          "/home/lluis/Arduino/libraries/FastLED/examples/DemoReel100",
          "/home/lluis/Arduino/libraries/FastLED/examples/Fire2012",
          "/home/lluis/Arduino/libraries/FastLED/examples/Fire2012WithPalette",
          "/home/lluis/Arduino/libraries/FastLED/examples/FirstLight",
          "/home/lluis/Arduino/libraries/FastLED/examples/Multiple/ArrayOfLedArrays",
          "/home/lluis/Arduino/libraries/FastLED/examples/Multiple/MirroringSample",
          "/home/lluis/Arduino/libraries/FastLED/examples/Multiple/MultiArrays",
          "/home/lluis/Arduino/libraries/FastLED/examples/Multiple/MultipleStripsInOneArray",
          "/home/lluis/Arduino/libraries/FastLED/examples/Multiple/OctoWS2811Demo",
          "/home/lluis/Arduino/libraries/FastLED/examples/Multiple/ParallelOutputDemo",
          "/home/lluis/Arduino/libraries/FastLED/examples/Noise",
          "/home/lluis/Arduino/libraries/FastLED/examples/NoisePlayground",
          "/home/lluis/Arduino/libraries/FastLED/examples/NoisePlusPalette",
          "/home/lluis/Arduino/libraries/FastLED/examples/Pintest",
          "/home/lluis/Arduino/libraries/FastLED/examples/Ports/PJRCSpectrumAnalyzer",
          "/home/lluis/Arduino/libraries/FastLED/examples/RGBCalibrate",
          "/home/lluis/Arduino/libraries/FastLED/examples/RGBSetDemo",
          "/home/lluis/Arduino/libraries/FastLED/examples/SmartMatrix",
          "/home/lluis/Arduino/libraries/FastLED/examples/XYMatrix"
        ],
        "install_dir": "/home/lluis/Arduino/libraries/FastLED",
        "license": "Unspecified",
        "location": 1,
        "maintainer": "Daniel Garcia \[email protected]\u003e",
        "name": "FastLED",
        "paragraph": "Multi-platform library for controlling dozens of different types of LEDs along with optimized math, effect, and noise functions.",
        "provides_includes": [
          "FastLED.h",
          "bitswap.h",
          "chipsets.h",
          "color.h",
          "colorpalettes.h",
          "colorutils.h",
          "controller.h",
          "cpp_compat.h",
          "dmx.h",
          "fastled_config.h",
          "fastled_delay.h",
          "fastled_progmem.h",
          "fastpin.h",
          "fastspi.h",
          "fastspi_bitbang.h",
          "fastspi_dma.h",
          "fastspi_nop.h",
          "fastspi_ref.h",
          "fastspi_types.h",
          "hsv2rgb.h",
          "led_sysdefs.h",
          "lib8tion.h",
          "noise.h",
          "pixelset.h",
          "pixeltypes.h",
          "platforms.h",
          "power_mgt.h"
        ],
        "sentence": "Multi-platform library for controlling dozens of different types of LEDs along with optimized math, effect, and noise functions.",
        "source_dir": "/home/lluis/Arduino/libraries/FastLED",
        "version": "3.3.2",
        "website": "https://github.com/FastLED/FastLED"
      },
      "release": {
        "architectures": [
          "*"
        ],
        "author": "Daniel Garcia",
        "category": "Display",
        "maintainer": "Daniel Garcia \[email protected]\u003e",
        "paragraph": "Multi-platform library for controlling dozens of different types of LEDs along with optimized math, effect, and noise functions.",
        "sentence": "Multi-platform library for controlling dozens of different types of LEDs along with optimized math, effect, and noise functions.",
        "types": [
          "Contributed"
        ],
        "version": "3.4.0",
        "website": "https://github.com/FastLED/FastLED"
      }
    }
  ]
]

Does this PR introduce a breaking change, and is titled accordingly?

No

Other information

See comment in #2104 (comment)

@CLAassistant
Copy link

CLAassistant commented Mar 15, 2023

CLA assistant check
All committers have signed the CLA.

@lluiscampos lluiscampos force-pushed the fix-invalid-json-outdated-command branch from fbb9ea7 to 9f728ce Compare March 15, 2023 10:06
@codecov
Copy link

codecov bot commented Mar 15, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.13 ⚠️

Comparison is base (d5eb0b7) 35.09% compared to head (673e3c2) 34.96%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2111      +/-   ##
==========================================
- Coverage   35.09%   34.96%   -0.13%     
==========================================
  Files         232      232              
  Lines       20496    20570      +74     
==========================================
  Hits         7193     7193              
- Misses      12455    12529      +74     
  Partials      848      848              
Flag Coverage Δ
unit 34.96% <0.00%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
internal/cli/core/list.go 0.00% <0.00%> (ø)
internal/cli/lib/list.go 0.00% <0.00%> (ø)
internal/cli/outdated/outdated.go 0.00% <0.00%> (ø)

... and 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@lluiscampos lluiscampos marked this pull request as draft March 15, 2023 10:18
@lluiscampos lluiscampos force-pushed the fix-invalid-json-outdated-command branch 2 times, most recently from 0eb6817 to abc717a Compare March 16, 2023 09:06
@lluiscampos lluiscampos marked this pull request as ready for review March 16, 2023 09:25
@lluiscampos
Copy link
Contributor Author

The code is ready for review now. There are some test failures but I believe they are spurious errors due to upstream timeouts or other glitches.

Any feedback is welcome! Thanks

Copy link
Member

@cmaglie cmaglie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some changes that I'd like to see implemented.

This is a breaking change, the file docs/UPGRADING.md must be updated with a note describing the breaking change in the JSON output of the outdated command that will be effective in the following 0.32.0 release (an example with the old and new will be sufficient).

Thank you for the very good PR @lluiscampos!

@cmaglie cmaglie self-assigned this Mar 16, 2023
@cmaglie cmaglie added type: imperfection Perceived defect in any part of project topic: CLI Related to the command line interface labels Mar 16, 2023
Copy link
Contributor Author

@lluiscampos lluiscampos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some changes that I'd like to see implemented.

I followed up accordingly.

This is a breaking change, the file docs/UPGRADING.md must be updated with a note describing the breaking change in the JSON output of the outdated command that will be effective in the following 0.32.0 release (an example with the old and new will be sufficient).

Right. I originally didn't consider it a breaking change being a bugfix. But you are technically right! I have added it now.

Additionally, I realized that this also fixes the YAML output (which was also two independent objects) so I noted that as well in the UPGRADING.md and the commit message.

Thank you for the very good PR @lluiscampos!

Thank you for the swift review!

@lluiscampos lluiscampos force-pushed the fix-invalid-json-outdated-command branch from abc717a to 84c12b8 Compare March 17, 2023 09:05
@lluiscampos lluiscampos changed the title Fix invalid JSON output for outdated command Fix invalid JSON and YAML outputs for outdated command Mar 17, 2023
Fixes issue arduino#2104

The code for `internal/cli/core` and `internal/cli/lib` has been
refactored so that we can use only the `Get` functions from
`internal/cli/outdated` package and compose there composited object.

For regular text output, the new table will have some extra fields that
either for platforms or for libraries will be blank.

For JSON and YAML output, the resulting object will have the top-level
keys `platforms` and `libraries` which contain, respectively, the array
of outaded platforms and outdated libraries.

Signed-off-by: Lluís Martínez <[email protected]>
@lluiscampos lluiscampos force-pushed the fix-invalid-json-outdated-command branch from 84c12b8 to 673e3c2 Compare March 17, 2023 09:18
@lluiscampos lluiscampos requested a review from cmaglie March 17, 2023 09:36
@cmaglie cmaglie merged commit a8b52ea into arduino:master Mar 17, 2023
kittaakos pushed a commit to kittaakos/arduino-cli that referenced this pull request Mar 21, 2023
Fixes issue arduino#2104

The code for `internal/cli/core` and `internal/cli/lib` has been
refactored so that we can use only the `Get` functions from
`internal/cli/outdated` package and compose there composited object.

For regular text output, the new table will have some extra fields that
either for platforms or for libraries will be blank.

For JSON and YAML output, the resulting object will have the top-level
keys `platforms` and `libraries` which contain, respectively, the array
of outaded platforms and outdated libraries.

Signed-off-by: Lluís Martínez <[email protected]>
@lluiscampos lluiscampos deleted the fix-invalid-json-outdated-command branch March 29, 2023 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: CLI Related to the command line interface type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid JSON output for outdated command
3 participants